#include "Func.hpp"

void TestInsertSort()
{
    std::vector<int> num = {2, 5, 8, 3, 6, 9, 1, 4, 7};
    InsertSort(num);
    Print(num);
    IsTrue(num);
}

void TestOp()
{
    int N = 1000000, cnt = 0;
    std::vector<int> n1(N);
    std::vector<int> n2(N);
    std::vector<int> n3(N);
    std::vector<int> n4(N);
    std::vector<int> n5(N);
    std::vector<int> n6(N);
    for (int i = 0; i < N; i++)
    {
        n1[i] = (rand() % 100000000) + cnt++;
        // n1[i] = i;
        // n1[i] = N-i;
        // n1[i] = 10000;
        n2[i] = n1[i];
        n3[i] = n2[i];
        n4[i] = n3[i];
        n5[i] = n4[i];
        n6[i] = n5[i];
    }

    // int begin1 = clock();
    // InsertSort(n1);
    // int end1 = clock();
    // printf("n1 Is True?");
    // IsTrue(n1);

    long int begin2 = clock();
    ShellSort(n2);
    long int end2 = clock();
    // Print(n2);
    printf("n2 Is True?\n");
    IsTrue(n2);

    long int begin3 = clock();
    QuickSort(n3, 0, N - 1);
    long int end3 = clock();
    // Print(n2);
    printf("n3 Is True?\n");
    IsTrue(n3);

    long int begin4 = clock();
    QuickSortNoR(n4, 0, N - 1);
    long int end4 = clock();
    // Print(n2);
    printf("n4 Is True?\n");
    IsTrue(n4);

    long int begin5 = clock();
    QuickSortNoR(n5, 0, N - 1);
    long int end5 = clock();
    // Print(n2);
    printf("n5 Is True?\n");
    IsTrue(n5);

    long int begin6 = clock();
    QuickSortNoR(n6, 0, N - 1);
    long int end6 = clock();
    // Print(n2);
    printf("n6 Is True?\n");
    IsTrue(n6);

    // printf("InsertSort: %d\n", end1 - begin1);
    printf("ShellSort: %ld\n", end2 - begin2);
    printf("QuickSort: %ld\n", end3 - begin3);
    printf("QuickSortNoR: %ld\n", end4 - begin4);
    printf("MergeSort: %ld\n", end5 - begin5);
    printf("MergeSortNoR: %ld\n", end6 - begin6);
}

void TestShellSort()
{
    std::vector<int> nums = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    ShellSort(nums);
    Print(nums);
    IsTrue(nums);
}

void TestQuickSort()
{
    std::vector<int> nums = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    // std::vector<int> nums = {49,38,65,97,76,13,27,49};
    QuickSort(nums, 0, nums.size() - 1);
    Print(nums);
    IsTrue(nums);
}

void TestMergeSort()
{
    std::vector<int> nums = {10, 6, 7, 1, 3, 9, 4, 2};
    std::vector<int> tmp(nums.size());
    // std::vector<int> nums = {49,38,65,97,76,13,27,49};
    MergeSort(nums, 0, nums.size() - 1, tmp);
    Print(nums);
    IsTrue(nums);
}

void TestMergeSortNoR()
{
    std::vector<int> nums = {10, 6, 7, 1, 3, 9, 4, 2};
    std::vector<int> tmp(nums.size());
    // std::vector<int> nums = {49,38,65,97,76,13,27,49};
    MergeSortNoR(nums, tmp);
    Print(nums);
    IsTrue(nums);
}

void TestQuickSortNoR()
{
    std::vector<int> nums = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    // std::vector<int> nums = {49,38,65,97,76,13,27,49};
    QuickSortNoR(nums, 0, nums.size() - 1);
    Print(nums);
    IsTrue(nums);
}

int main()
{
    // std::cout << "hello world" << std::endl;
    srand(time(0));
    // TestInsertSort();
    TestOp();
    // TestShelSort();
    // TestQuickSort();
    // TestQuickSortNoR();
    // TestMergeSort();
    // TestMergeSortNoR();
    return 0;
}
